/**
 * 
 */
package com.nervytech.tutorcruise.application.util;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.ow2.chameleon.url.shortener.service.URLShortenerService;

/**
 * @author ADMIN
 *
 */
public class TinyURLUtils implements URLShortenerService {
	
		public static String getTinyUrl(String fullUrl) throws HttpException, IOException {
			HttpClient httpclient = new HttpClient();
	 
			// Prepare a request object
			HttpMethod method = new GetMethod("http://tinyurl.com/api-create.php"); 
			method.setQueryString(new NameValuePair[]{new NameValuePair("url",fullUrl)});
			httpclient.executeMethod(method);
			String tinyUrl = method.getResponseBodyAsString();
			//method.releaseConnection();
			return tinyUrl;
		}
		
		@Override
		public String getShortURL(String arg0) throws Exception {
			// TODO Auto-generated method stub
			return null;
		}
		
		public static void main(String args[]){
			try {
				System.out.println("TINY URLLLLLLL "+getTinyUrl("http://localhost:18080/tutorcruise/pub/class/view/id/bdcdded0-2c14-11e2-8d68-009c021e16c4"));
			} catch (HttpException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
}
